{layout name="main"/}
<style>
    .modal-backdrop {
        display: none !important;
    }
</style>
<div class="wrapper wrapper-content animated fadeInUp">
    <div class="row">
        <div class="col-sm-12">

            <div class="ibox">
                <div class="ibox-title">
                    <h5>{$title}</h5>
                </div>
                <div class="ibox-content">
                  <form method="post" action="" class="form-horizontal m-t" id="article">
                  <div class="form-group">
                      <label class="col-sm-3 control-label">分类名称</label>
                      <div class="col-sm-9">
                          <select class="form-control m-b" name="type">
                              {foreach name="categories" item="cate" key="k"}
                              <option value="{$k}" {if condition="$cate==$article:type"}selected{/if}>{$cate}</option>
                              {/foreach}
                          </select>
                      </div>
                  </div>
                  <div class="form-group">
                      <label class="col-sm-3 control-label">标题</label>
                      <div class="col-sm-9">
                          <input type="text" class="form-control" name="title" value="{$article:title}">
                      </div>
                  </div>
                  <div class="form-group">
                      <label class="col-sm-3 control-label">内容</label>
                      <div class="col-sm-9">
                          <div class="summernote">{$article:content}</div>
                      </div>
                  </div>
                  <div class="form-group">
                      <div class="col-sm-4 col-sm-offset-3">
                          <button class="btn btn-primary" type="button" onclick="add()">提交</button>
                      </div>
                  </div>
              </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    function add() {
        var content = $(".summernote").code();
        var articledata = $("#article").serialize()+'&content='+content;
        post({
            url: "{$thispageurl}",
            data: articledata,
            success: function(res) {
                swal({
                    title: 'success',
                    text: res.message,
                    type: "success"
                }, function() {
                    toUrl("{:url('admin/Article/showlist')}");
                });
            },
            error: function(error) {
                swal("错误", JSON.parse(error.responseText).message, "error");
            }
        });
    }

    $(document).ready(function() {
        $(".summernote").summernote({
            lang: "zh-CN",
            height: 300,
            toolbar: [
                ["style", ["style"]],
                ["font", ["bold", "italic", "underline", "clear"]],
                ["fontname", ["fontname"]],
                ["color", ["color"]],
                ["para", ["ul", "ol", "paragraph"]],
                ["height", ["height"]],
                ["table", ["table"]],
                ["insert", ["link", "picture"]]
            ],
        });
    });

</script>
